package views
{
	import assists.resource.ResourceLoaderData;
	
	import inerface.IViewSpotDetailPanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import message.CommentBackResult;
	
	import panel.viewSpots.ViewSpotDetailNew;
	
	public class ViewSpotDetailView extends ViewSubBase
	{
		private var _openID:int;
		private var _panel:IViewSpotDetailPanel;
		private var _data:Object;
		private var _list:Array;
		private var _type:uint;
		
		public function ViewSpotDetailView()
		{
			super();
		}
		
		public function showData(data:Object,type:int):void
		{
			view.loadWait.show();
			_data = data;
			_type = type;
			var resList:Array = [];
			var preStr:String = "";
			if(_type == ClientConstants.DETAIL_HOUSE)
			{
				preStr = "hotel/";
			}else if(_type == ClientConstants.DETAIL_VIEWSPOT)
			{
				preStr = "viewSpot/";
			}else if(_type == ClientConstants.DETAIL_SHOP)
			{
				preStr = "scenicShop/";
			}else if(_type == ClientConstants.DETAIL_EAT)
			{
				preStr = "eat/";
			}
			if(_data.picList.length > 0)
			{
				for(var i:int=0;i<_data.picList.length;i++)
				{
					var url:String = this.data.uri.getViewSpotDetailPic(preStr,_data.picList[i]);
					var resData:ResourceLoaderData = new ResourceLoaderData(url);
					_data["picUrl"].push(url);
					resList.push(resData);
				}
				this.resourceLoader.load(resList,new Function,show);
			}else
			{
				show();
			}
		}
		
		override public function show():void
		{
			this.registerMessageHandler(CommentBackResult.CMD,commentBackHandler);
			this.data.viewSpot.requestCommitData(_data.id,1);
			render();
		}
		
		private function commentBackHandler(value:CommentBackResult):void
		{
			if(_panel)
			{
				_panel.update(_data);
			}
		}
		
		override protected function render():void
		{
			if(view.loadWait.instage)
			{
				view.loadWait.close();
			}
			if(_type == ClientConstants.DETAIL_EAT)
			{
				_list = this.data.viewSpot.resturantList;
			}else if(_type == ClientConstants.DETAIL_VIEWSPOT)
			{
				_list = this.data.viewSpot.viewSpotsData.spotList;
			}else if(_type == ClientConstants.DETAIL_SHOP)
			{
				_list = this.data.viewSpot.shopList;
			}else if(_type == ClientConstants.DETAIL_COLLECT)
			{
				_list = [];
			}else if(_type == ClientConstants.DETAIL_HOUSE){
				_list = data.viewSpot.hotelList;
			}
			
			if(!_panel)
			{
				_panel = new ViewSpotDetailNew() as IViewSpotDetailPanel;
				_panel.init(view.layout.stage,view.resourceLoader,lang,this.data.uri);
				_panel.openTextPanel = view.textPanel.showDataPanel;
				_panel.openCommentPanel = view.commentList.show;
				_panel.openMap = view.navigationTypeChoose.showData;
				_panel.openWeibo = view.weico.show;
				_panel.addPath = addToPath;
				_panel.showLocation = showLocation;
			}
			_panel.onPanelTyep = _type;
			this.addView(_panel);
			_panel.show(_data,_list);
		}
		
		private function addToPath(obj:Object):void
		{
			var bool:Boolean = data.choosePath.element(obj);
			if(bool == true){
				view.alert.showAlert("添加成功","确定");
				return;
			}else{
				view.alert.showAlert("当前编辑路线中已添加该地点","返回");
				return;
			}
		}
		
		private function showLocation(obj:*):void
		{
			view.showLocation.objInfo = obj;
			view.showLocation.show();
		}
		
		public function set openID(value:uint):void
		{
			_openID = value;
		}
		
		override public function clear():void
		{
			_panel.clear();
			_panel = null;
			this.cancelMessageHandler(CommentBackResult.CMD,commentBackHandler);
		}
		
	}
}